/*
ID: quxiao82
LANG: C++
PROG: butter
*/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
using namespace std;

const int VNUM = 501;
const int PNUM = 801;

struct Node
{
     int v;
     int len;
};

int n, p, e;
vector<Node> g[PNUM];
int cowLocation[VNUM];
int minDis[PNUM][PNUM];
int pChecked[PNUM];
int inSet[PNUM];
/*int cowNum[PNUM];*/
queue<int> q;
int inQueue[PNUM];
set<int> notInSet;

void Input ()
{
     int i, tmp, from, to, len;
     Node node;
     scanf("%d%d%d", &n, &p, &e);
     for (i = 1; i <= n; i ++)
     {
          scanf("%d", &tmp);
          cowLocation[i] = tmp;
//          ++ cowNum[tmp];
     }
     for (i = 0; i < e; i ++)
     {
          scanf("%d%d%d", &from, &to, &len);
          if ( from == to )
               continue;
          node.len = len;
          node.v = to;
          g[from].push_back(node);
          node.v = from;
          g[to].push_back(node);
     }
}

void SPFA (int from)
{
     int i, tmpV, tmpLen, curV;
     for (i = 1; i <= p; i ++)
          minDis[from][i] = minDis[i][from] = -1;
     minDis[from][from] = 0;
     while (!q.empty())
          q.pop();
     q.push(from);

     while ( !q.empty() )
     {
          curV = q.front();
          q.pop();
          inQueue[curV] = 0;
          for (i = 0; i < g[curV].size(); i ++)
          {
               tmpV = g[curV][i].v;
               tmpLen = g[curV][i].len;
               if ( minDis[from][tmpV] == -1 || (minDis[from][curV] + tmpLen < minDis[from][tmpV]) )
               {
                    minDis[from][tmpV] = minDis[tmpV][from] = minDis[from][curV] + tmpLen;
                    if ( !inQueue[tmpV] )
                    {
                         q.push(tmpV);
                         inQueue[tmpV] = 1;
                    }
               }
          }
     }

//      for (i = 1; i <= p; i ++)
//           printf("%d=>%d: %d\n", from, i, minDis[from][i]);
}

void Solve ()
{
     int i, j, minSum, sum;
     memset(pChecked, 0, sizeof(pChecked));
     for (i = 1; i <= n; i ++)
     {
          if ( pChecked[cowLocation[i]] )
               continue;
          pChecked[cowLocation[i]] = 1;
          SPFA(cowLocation[i]);
     }

     minSum = -1;
     for (i = 1; i <= p; i ++)
     {
          sum = 0;
          for (j = 1; j <= n; j ++)
          {
               if ( i == cowLocation[j] )
                    continue;
               if ( minDis[i][cowLocation[j]] == -1 )
               {
                    sum == -1;
                    break;
               }
               sum += minDis[i][cowLocation[j]];
          }
          if ( sum == -1 )
               continue;
          if ( minSum == -1 || sum < minSum )
               minSum = sum;
     }
     printf("%d\n", minSum);
}

/*
void Dij (int fromV)
{
//     printf("Dij(%d)\n", fromV);
     int i, k, minD, minIdx;
     int tmpV, tmpLen, curCowNum = 0;
     memset(inSet, 0, sizeof(inSet));
     inSet[fromV] = 1;
     curCowNum += cowNum[fromV];
     for (i = 1; i <= p; i ++)
          minDis[fromV][i] = minDis[i][fromV] = -1;
     for (i = 0; i < g[fromV].size(); i ++)
     {
          tmpV = g[fromV][i].v;
          tmpLen = g[fromV][i].len;
          minDis[fromV][tmpV] = minDis[tmpV][fromV] = tmpLen;
     }

     for (k = 0; k < p-1; k ++)
     {
          minD = -1;
          for (i = 1; i <= p; i ++)
          {
               if ( inSet[i] )
                    continue;
               if ( minDis[fromV][i] != -1 && (minD == -1 || minDis[fromV][i] < minD) )
               {
                    minD = minDis[fromV][i];
                    minIdx = i;
               }
          }
          if ( minD == -1 )
               break;
//          printf("find: %d\nminD: %d\n", minIdx, minD);
          inSet[minIdx] = 1;
          curCowNum += cowNum[minIdx];
          if ( curCowNum == n )
               break;
          for (i = 0; i < g[minIdx].size(); i ++)
          {
               tmpV = g[minIdx][i].v;
               tmpLen = g[minIdx][i].len;
               if ( !inSet[tmpV] && (minDis[fromV][tmpV] == -1 || minD + tmpLen < minDis[fromV][tmpV]) )
               {
                    minDis[fromV][tmpV] = minDis[tmpV][fromV] = minD + tmpLen;
               }
          }
     }
}

void Solve ()
{
     int i, j, minSum, sum;
     memset(pChecked, 0, sizeof(pChecked));
     for (i = 1; i <= n; i ++)
     {
          if ( pChecked[cowLocation[i]] )
               continue;
          pChecked[cowLocation[i]] = 1;
          Dij(cowLocation[i]);
     }

     minSum = -1;
     for (i = 1; i <= p; i ++)
     {
          sum = 0;
          for (j = 1; j <= n; j ++)
          {
               if ( i == cowLocation[j] )
                    continue;
               if ( minDis[i][cowLocation[j]] == -1 )
               {
                    sum == -1;
                    break;
               }
               sum += minDis[i][cowLocation[j]];
          }
          if ( sum == -1 )
               continue;
          if ( minSum == -1 || sum < minSum )
               minSum = sum;
     }
}
*/


int main ()
{
     freopen("butter.in", "r", stdin);
     freopen("butter.out", "w", stdout);

     Input ();
     Solve ();

     return 0;
}